﻿Public Class clsPlanet
    Inherits clsStar

    Private m_pParentSpaceObject As ISpaceObject

    Private m_dAngle As Double
    Private m_dRadius1 As Single
    Private m_dRadius2 As Single

    Private m_dCurrentRadius As Single

    Public Sub New(ByVal Radius1 As Single, ByVal Radius2 As Single, ByRef pParentSpaceObject As ISpaceObject)
        m_dAngle = (New Random).NextDouble() * Math.PI * 2
        m_dRadius1 = Radius1
        m_dRadius2 = Radius2
        m_pParentSpaceObject = pParentSpaceObject

    End Sub
    Public Sub New(ByVal dStartAngle As Double, ByVal Radius1 As Single, ByVal Radius2 As Single, ByVal pParentSpaceObject As ISpaceObject)
        m_dAngle = dStartAngle
        m_dRadius1 = Radius1
        m_dRadius2 = Radius2
        m_pParentSpaceObject = pParentSpaceObject
    End Sub

    Public Sub Move(ByVal dBaseVelocity As Double)
        Dim dVelocity As Double
        If m_dCurrentRadius > 0 Then
            dVelocity = dBaseVelocity / m_dCurrentRadius
            If TypeOf (m_pParentSpaceObject) Is clsPlanet Then
                dVelocity *= 0.4F
            End If

        End If

        m_dAngle += dVelocity

        m_dAngle = m_dAngle Mod (Math.PI * 2)
    End Sub

    Public Overrides Function GetCurrentPosition() As System.Drawing.PointF
        Dim pLocation As New PointF()

        pLocation.X = Math.Cos(m_dAngle) * m_dRadius1
        pLocation.Y = Math.Sin(m_dAngle) * m_dRadius2

        m_dCurrentRadius = Math.Sqrt(Math.Pow(pLocation.X, 2) + Math.Pow(pLocation.Y, 2))

        Dim pParentPosition As PointF = m_pParentSpaceObject.GetCurrentPosition
        pLocation.X += pParentPosition.X
        pLocation.Y += pParentPosition.Y



        Return pLocation
    End Function

    'Public Overrides Sub Draw(ByRef g As System.Drawing.Graphics)
    '    Dim pCurrentPosition As PointF = GetCurrentPosition()
    '    g.DrawEllipse(Pens.White, New RectangleF(pCurrentPosition, New SizeF(1.0, 1.0)))
    '    'g.DrawString(m_dCurrentRadius.ToString, New Font("Arial", 10), Brushes.White, pCurrentPosition)
    'End Sub
End Class
